package cn.hdu.liang.io;

import java.io.File;

public class MakeDirectories {
    private static void usage() {

    }

    private static void fileData(File file) {
        System.out.println("绝对路径" + file.getAbsolutePath());
        System.out.println("可读" + file.canRead());
        System.out.println("可写" + file.canWrite());
        System.out.println("可执行" + file.canExecute());
        System.out.println("文件名" + file.getName());
        System.out.println("父目录" + file.getParent());
        System.out.println("路径" + file.getPath());
        System.out.println("长度" + file.length());
        System.out.println("上次修改" + file.lastModified());

        if(file.isFile()) {
            System.out.println("这是个文件");
        } else {
            System.out.println("这是个目录");
        }
    }

    public static void main(String[] args) {
        if(args[0].equals("-r")) {
            File old = new File(args[1]);
            File rname = new File(args[2]);
            old.renameTo(rname);
            fileData(old);
            fileData(rname);
            return;
        }
        int count = 0;
        boolean del = false;
        if(args[0].equals("-d")) {
            count++;
            del = true;
        }
        count--;
        while(++count < args.length) {
            File file = new File(args[count]);
            if(file.exists()) {
                System.out.println(file + " 存在");
                if(del) {
                    System.out.println("删除中" + file);
                    file.delete();
                    file.deleteOnExit();
                }
            } else {
                if(!del) {
                    file.mkdirs();
                    System.out.println("创建中" + file);
                }
            }
            fileData(file);
        }
    }

}
